package com.cn.config;

/**
 * 功能描述: <br>
 *
 * @program: wx-nimi-bank
 * @description:
 * @author: Mr.TYJ
 * @create: 2022-06-01 20:46
 **/
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@JsonComponent
public class JsonSerializerManage {
    //Springboot + vue 后端把Long类型的数据传给前端，前端可能会出现精度丢失的情况，以及解决方案
    //全局处理 Springboot 2.X配置
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Jackson2ObjectMapperBuilderCustomizer cunstomizer = new Jackson2ObjectMapperBuilderCustomizer() {
            @Override
            public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
                jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
          }
        };
        return cunstomizer;
    }

}
